﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDOS.Objects;
using Microsoft.Xna.Framework;

namespace DDOS.Game_State
{
    class Level1 : LevelLayer
    {
        Random ran = new Random();
        public Level1(Player plyr)
        {
            SoundManager.Instance.Play(SoundManager.Instance.InGame, true);
            //plyr.InitialCoordinates(600, 400);
            //This was moving the player without adjusting his bounding objects after he was placed in the first room

            base.curRoom = new Room();
            base.curRoom.InitializeComponents(plyr);
            base.nextRoom = null;

            Enemy0 e0 = new Enemy0();
            Enemy0 e1 = new Enemy0();
            Enemy0 e2 = new Enemy0();
            Enemy0 e3 = new Enemy0();
            e0.InitialCoordinates(300, 100);
            e1.InitialCoordinates(900, 100);
            e2.InitialCoordinates(900, 500);
            e3.InitialCoordinates(300, 500);
            e0.init_random(ran);
            e1.init_random(ran);
            e2.init_random(ran);
            e3.init_random(ran);
            e0.InitializeComponents();
            e1.InitializeComponents();
            e2.InitializeComponents();
            e3.InitializeComponents();
            e0.set_room(curRoom);
            e1.set_room(curRoom);
            e2.set_room(curRoom);
            e3.set_room(curRoom);
            base.curRoom.add_enemy(e0);
            base.curRoom.add_enemy(e1);
            base.curRoom.add_enemy(e2);
            base.curRoom.add_enemy(e3);

            Wall hw0 = new Wall(ImageManager2D.Instance.Wall, new BoundingRectangle(0, -200, 640, 50));
            Wall hw1 = new Wall(ImageManager2D.Instance.Wall2, new BoundingRectangle(640, -200, 1280, 50));
            Wall hw2 = new Wall(ImageManager2D.Instance.Wall, new BoundingRectangle(0, 670, 640, 1200));
            Wall hw3 = new Wall(ImageManager2D.Instance.Wall2, new BoundingRectangle(640, 670, 1280, 1200));

            Wall vw0 = new Wall(ImageManager2D.Instance.Wall_Vertical, new BoundingRectangle(0, 50, 150, 360));
            Wall vw1 = new Wall(ImageManager2D.Instance.Wall2_Vertical, new BoundingRectangle(0, 360, 150, 670));
            Wall vw2 = new Wall(ImageManager2D.Instance.Wall_Vertical, new BoundingRectangle(1130, 50, 1280, 360));
            Wall vw3 = new Wall(ImageManager2D.Instance.Wall_Vertical, new BoundingRectangle(1130, 360, 1280, 670));


            base.curRoom.add_wall(hw0);
            base.curRoom.add_wall(hw1);
            base.curRoom.add_wall(hw2);
            base.curRoom.add_wall(hw3);

            base.curRoom.add_wall(vw0);
            base.curRoom.add_wall(vw1);
            base.curRoom.add_wall(vw2);
            base.curRoom.add_wall(vw3);

            Room room0 = new Room();

            room0.InitializeComponents(plyr);

            room0.add_wall(hw0);
            room0.add_wall(hw1);
            room0.add_wall(hw2);
            room0.add_wall(hw3);

            room0.add_wall(vw0);
            room0.add_wall(vw1);
            room0.add_wall(vw2);
            room0.add_wall(vw3);
       

            
            Room room1 = new Room();

            room1.InitializeComponents(plyr);

            room1.add_wall(hw0);
            room1.add_wall(hw1);
            room1.add_wall(hw2);
            room1.add_wall(hw3);

            room1.add_wall(vw0);
            room1.add_wall(vw1);
            room1.add_wall(vw2);
            room1.add_wall(vw3);

            Room room2 = new Room();

            room2.InitializeComponents(plyr);

            room2.add_wall(hw0);
            room2.add_wall(hw1);
            room2.add_wall(hw2);
            room2.add_wall(hw3);

            room2.add_wall(vw0);
            room2.add_wall(vw1);
            room2.add_wall(vw2);
            room2.add_wall(vw3);

            Room room3 = new Room();

            room3.InitializeComponents(plyr);

            room3.add_wall(hw0);
            room3.add_wall(hw1);
            room3.add_wall(hw2);
            room3.add_wall(hw3);

            room3.add_wall(vw0);
            room3.add_wall(vw1);
            room3.add_wall(vw2);
            room3.add_wall(vw3);

            Room room4 = new Room();


            room4.InitializeComponents(plyr);

            room4.add_wall(hw0);
            room4.add_wall(hw1);
            room4.add_wall(hw2);
            room4.add_wall(hw3);

            room4.add_wall(vw0);
            room4.add_wall(vw1);
            room4.add_wall(vw2);
            room4.add_wall(vw3);

            Room room5 = new Room();
            room5.InitializeComponents(plyr);

            room5.add_wall(hw0);
            room5.add_wall(hw1);
            room5.add_wall(hw2);
            room5.add_wall(hw3);

            room5.add_wall(vw0);
            room5.add_wall(vw1);
            room5.add_wall(vw2);
            room5.add_wall(vw3);



            TransitionObject t = new TransitionObject(room0, this, new BoundingCircle(300, 375, 25), new Vector2(300, 375), ImageManager2D.Instance.Hole, new Vector2(700,375),false);
            TransitionObject t2 = new TransitionObject(room1, this, new BoundingCircle(900, 375, 25), new Vector2(900, 375), ImageManager2D.Instance.Hole, new Vector2(500, 375),false);
            TransitionObject t3 = new TransitionObject(curRoom, this, new BoundingCircle(300, 100, 25), new Vector2(300, 100), ImageManager2D.Instance.Hole, new Vector2(700, 375),false);
            TransitionObject t4 = new TransitionObject(curRoom, this, new BoundingCircle(900,375,25), new Vector2(900,375), ImageManager2D.Instance.Hole, new Vector2(500, 375),false);

            TransitionObject t6 = new TransitionObject(room2, this, new BoundingCircle(175, 100, 25), new Vector2(175, 100), ImageManager2D.Instance.Hole, new Vector2(175, 200), false);
            TransitionObject t7 = new TransitionObject(room0, this, new BoundingCircle(175, 100, 25), new Vector2(175, 100), ImageManager2D.Instance.Hole, new Vector2(175, 200), false);

            TransitionObject t8 = new TransitionObject(room3, this, new BoundingCircle(900, 500, 25), new Vector2(900, 500), ImageManager2D.Instance.Hole, new Vector2(800, 200), false);
            TransitionObject t9 = new TransitionObject(room1, this, new BoundingCircle(900, 100, 25), new Vector2(900, 100), ImageManager2D.Instance.Hole, new Vector2(900, 300), false);

            TransitionObject t10 = new TransitionObject(room2, this, new BoundingCircle(300, 375, 25), new Vector2(300, 375), ImageManager2D.Instance.Hole, new Vector2(700, 375), false);
            TransitionObject t11 = new TransitionObject(room3, this, new BoundingCircle(900, 375, 25), new Vector2(900, 375), ImageManager2D.Instance.Hole, new Vector2(500, 375), false);
            TransitionObject t12= new TransitionObject(room4, this, new BoundingCircle(300, 100, 25), new Vector2(300, 100), ImageManager2D.Instance.Hole, new Vector2(700, 375), false);
            TransitionObject t13 = new TransitionObject(room4, this, new BoundingCircle(900, 375, 25), new Vector2(900, 375), ImageManager2D.Instance.Hole, new Vector2(500, 375), false);

            TransitionObject tboss = new TransitionObject(room5, this, new BoundingCircle(600, 100, 25), new Vector2(600, 100), ImageManager2D.Instance.Hole, new Vector2(600, 375), true);

            base.curRoom.add_transition(t);
            base.curRoom.add_transition(t2);

            room0.add_transition(t4);
            room1.add_transition(t3);

            room0.add_transition(t6);
            room2.add_transition(t7);

            room1.add_transition(t8);
            room3.add_transition(t9);


            room4.add_transition(t10);
            room4.add_transition(t11);

            room2.add_transition(t13);
            room3.add_transition(t12);

            room4.add_transition(tboss);

            Boss1 boss = new Boss1();

            boss.init_target(plyr);


            Enemy0 eb1 = new Enemy0();
            Enemy0 eb2 = new Enemy0();
            Enemy0 er0 = new Enemy0();
            Enemy0 er1 = new Enemy0();
            Enemy0 er2 = new Enemy0();
            Enemy0 er3 = new Enemy0();

            er0.InitialCoordinates(640, 360);
            er1.InitialCoordinates(640, 360);
            er2.InitialCoordinates(640, 360);
            er3.InitialCoordinates(640, 360);

            eb1.InitialCoordinates(300, 100);
            eb2.InitialCoordinates(900, 100);
            boss.InitialCoordinates(640, 100);

            eb1.init_random(ran);
            eb2.init_random(ran);
            boss.init_random(ran);

            er0.init_random(ran);
            er1.init_random(ran);
            er2.init_random(ran);
            er3.init_random(ran);
           
            eb1.InitializeComponents();
            eb2.InitializeComponents();
            er0.InitializeComponents();
            er1.InitializeComponents();
            er2.InitializeComponents();
            er3.InitializeComponents();
            boss.InitializeComponents();

            eb1.set_room(room5);
            eb2.set_room(room5);
            er0.set_room(room0);
            er1.set_room(room1);
            er2.set_room(room2);
            er3.set_room(room3);

            room0.add_enemy(er0);
            room1.add_enemy(er1);
            room2.add_enemy(er2);
            room3.add_enemy(er3);
      
            room5.add_enemy(eb1);
            room5.add_enemy(eb2);
            room5.add_enemy(boss);
           

            base.curRoom.Activate();
            // room.Activate();
        }

        public override void Draw()
        {
            ScreenManager.Instance.CurrentSpriteBatch.Draw(ImageManager2D.Instance.LevelBackground2, Vector2.Zero, Color.White);
            base.Draw();
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gt)
        {
    
            if (base.nextRoom != null)
                base.intransition = true;
            if (base.intransition && halfway)
            {
                base.curRoom = nextRoom;
                base.nextRoom = null;
                base.halfway = false;
            }
            curRoom.Update(gt);

            base.Update(gt);
        }
    }
}
